from odoo import api, fields, models

RECHARGE_TYPE = [('stripe', 'Stripe支付'), ('bankcard', '银行卡')]


class RpCustomerBalance(models.Model):
    _name = 'rp.customer.balance'
    _description = '客户余额'
    _sql_constraints = [('unique_customer', 'UNIQUE (rp_customer_id)', '客户需要唯一')]

    rp_customer_id = fields.Many2one(string='客户', comodel_name='rp.customer', ondelete='cascade')
    total_balance = fields.Float(string='总余额', store=True)
    actual_price = fields.Float(string='实付金额')
    present_price = fields.Float(string='赠送金额')
    actual_radio = fields.Float(string='实付比率', store=True)
    present_radio = fields.Float(string='赠送比率', store=True)

    def name_get(self):
        result = []
        for rec in self:
            if self.rp_customer_id.first_name and self.rp_customer_id.last_name:
                result.append((rec.id, '{} ({}€) '.format(self.rp_customer_id.first_name + ' ' + self.rp_customer_id.last_name, str(self.total_balance))))
            else:
                result.append((rec.id, '{} €'.format(self.total_balance)))
        return result
